package com.lzwork.gpt.utility.common;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.lzwork.gpt.utility.caller.GptCallResult;
import com.lzwork.gpt.utility.caller.GptCaller;
import com.lzwork.utility.logger.LOGGER;

/**
 * Common server caller for LZ server framework
 * 
 * @author LiZheng
 * @date 2023年12月7日 上午10:20:02
 */

public class ParserCaller extends GptCaller
{
	public ParserCaller(String serverUrl, boolean dolog)
	{
		super(serverUrl);
		defLog = dolog;
	}
	
	protected boolean defLog;

	protected final static String chatApi = "chat";

	public GptCallResult callChat(String content, String desc, boolean dolog)
	{
		return callChat(content, desc, null, null, dolog);
	}

	public GptCallResult callChat(List<String> content, String desc, boolean dolog)
	{
		return callChat(content, desc, null, null, dolog);
	}

	public GptCallResult callChat(String content, String desc, List<String> history, List<String> systemPrompt, boolean dolog)
	{
		List<String> contents = new ArrayList<>();
		contents.add(content);
		return callChat(contents, desc, history, systemPrompt, dolog);
	}

	@Override
	public GptCallResult callChat(String content, List<String> history, List<String> systemPrompt)
	{
		return callChat(content, "", history, systemPrompt, defLog);
	}

	public GptCallResult callChat(List<String> content, String desc, List<String> history, List<String> systemPrompt,
			boolean dolog)
	{
		JSONObject param = new JSONObject();
		param.put("content", content);
		param.put("desc", desc);
		param.put("dolog", dolog);

		if (history == null)
			history = new ArrayList<>();
		param.put("history", history);
		
		if (systemPrompt == null)
			systemPrompt = new ArrayList<>();
		param.put("system", systemPrompt);

		if (dolog)
			LOGGER.log(LOGGER.NET, "Input param: " + param.toString());

		return call(url + chatApi, param);
	}
}
